package com.adtec.base.cloud.commons.utils;


import org.springframework.util.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CheckPhon {

  public static void main(String[] args) {
    CheckPhon checkPhon = new CheckPhon();
    boolean cellPhoneNo = checkPhon.isCellPhoneNo("17600800656");
    System.out.println(cellPhoneNo);
  }
  /**
   * 验证是否是正确合法的手机号码
   *
   * @param telephone 需要验证的打手机号码
   * @return 合法返回true，不合法返回false
   */
  public  boolean isCellPhoneNo(String telephone) {
    if (StringUtils.isEmpty(telephone)) {
      return false;
    }
    if (telephone.length() != 11) {
      return false;
    }
//    String regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$";
    String regex = "^((13[0-9])|(14[5-9])|(15([0-3]|[5-9]))|(16[6-7])|(17[1-8])|(18[0-9])|(19[1|3])|(19[5|6])|(19[8|9]))\\d{8}$";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(telephone);

    if (matcher.matches()) {
      return true;
    }
    return false;
  }
}
